package book;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
import database.*;
import databaseInterface.*;
import dataPO.*;
import others.*;

public class bookBLService extends UnicastRemoteObject implements bookInterface, Interface.bookInterface{
	BookManageInterface bm=new BookManage();
	CatalogManageInterface cm=new CatalogManage();
	
	public bookBLService()throws RemoteException{		
	}
	public ArrayList<BookPO> getBookByCategory(String Catalog)throws RemoteException{
	   	 ArrayList<BookPO> bp;
	   	 bm.connect();
		 bp=bm.queryByCatalog(Catalog);
	     bm.close();
	   	 return bp;
	}
	public ArrayList<BookPO> searchBookByTitle(String title)throws RemoteException{
		ArrayList<BookPO> bp;
		bm.connect();
		bp=bm.queryByTitle(title);
		bm.close();
		return bp;
	}
	public ArrayList<BookPO> searchBookByAuthor(String author)throws RemoteException{
		ArrayList<BookPO> bp;
		bm.connect();
		bp=bm.queryByAuthor(author);
		bm.close();
		return bp;
	}
	public ArrayList<BookPO> searchBookByPress(String press)throws RemoteException{
		ArrayList<BookPO> bp;
		bm.connect();
		bp=bm.queryByPress(press);
		bm.close();
		return bp;
	}
	public ArrayList<BookPO> searchBookByISBN(String isbn)throws RemoteException{
		ArrayList<BookPO> bp;
		bm.connect();
		bp=bm.queryByISBN(isbn);
		bm.close();
		return bp;
	}
	
	public ArrayList<String> getCatalog()throws RemoteException{
		cm.connect();
		ArrayList<String> cl=cm.query();
		cm.close();
		return cl;
	}
	public ResultMessage addBookCatalog(String catalog)throws RemoteException{
		boolean isexit=false;
		cm.connect();
		isexit=cm.exist(catalog);
		if(!isexit){
			cm.insert(catalog);
			cm.close();
			return ResultMessage.Succeed;
		}
		else{
			cm.close();
			return ResultMessage.Exist;
		}
	}
	public ResultMessage delBookCatalog(String catalog)throws RemoteException{
		cm.connect();
		cm.delete(catalog);
		cm.close();
		return ResultMessage.Succeed;
	}
}
